<?
	require_once('init.php');
	require_once('dataModel.php');
	if($_SESSION["UID"]=="" || $_SESSION['flag']!='6275ffcfb9cd8f95984b93b0a7bfcefd')
	{
		$h_tourl="login.php";
		header("Location:".$h_tourl);
		exit;
	}
	$GoodsID=$_GET['ID'];
	$Type=$_GET['Type'];
	$pgno=$_GET['pgno'];
    
    if ($Type==0)
    {
    	$Title="新增产品资料";
		$strSQL = "select * from goods where 1=0";
		$imtype="0";
	}
    else if ($Type==1)
    {
    	$Title="修改产品资料";
		$strSQL = "select * from goods where id='".$GoodsID."' ";
    }

	$db = MySQL::getInstance('','r-w'); 
	$DBR=$db->query($strSQL); 
  	$result=$db->fetch($DBR);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=<?='utf-8';?>" />
	<title><?=$AllPageTitle;?></title>
	<link href="css/CenterMenu.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" href="css/Buttonstyle.css" type="text/css" media="screen" />	
	
	<? include("alljs.php"); ?>
	
	<script language="javascript">
		function goback(pgno)
		{
			self.location='goodsmanager.php?pgno='+pgno
		}

		function ChangeNum()
		{
			value=$("#year").attr("value"); 
			$("#year").attr("value",value.replace(/[^\d]/g,''));
			
			value=$("#adviceprice").attr("value"); 
			$("#adviceprice").attr("value",value.replace(/[^\d]/g,''));

		}
		
		function CheckData()
		{
			value = $("#goodsid").attr("value");
	       	if( value=="")
	       	{
				parent.hiAlert("请输入货号!", '系统提示');
				$("#goodsid").focus();
				return false;
	        }

			value = $("#goodsname").attr("value");
	       	if( value=="")
	       	{
				parent.hiAlert("请输入品名!", '系统提示');
				$("#goodsname").focus();
				return false;
	        }

			value = $("#goodsname_e").attr("value");
	       	if( value=="")
	       	{
				parent.hiAlert("请输入品名(英文)！", '系统提示');
				$("#goodsname_e").focus();
				return false;
	        }

			value = $("#goodscolor").attr("value");
	       	if( value=="0")
	       	{
				parent.hiAlert("请选择颜色!", '系统提示');
				$("#goodscolor").focus();
				return false;
	        }

			value = $("#goodssort1").attr("value");
	       	if( value=="0")
	       	{
				parent.hiAlert("请选择类别1!", '系统提示');
				$("#goodssort1").focus();
				return false;
	        }

			value = $("#goodssort2").attr("value");
	       	if( value=="0")
	       	{
				parent.hiAlert("请选择类别2!", '系统提示');
				$("#goodssort2").focus();
				return false;
	        }

			value = $("#year").attr("value");
	       	if( value=="")
	       	{
				parent.hiAlert("请输入年份!", '系统提示');
				$("#year").focus();
				return false;
	        }

			value = $("#goodsseason").attr("value");
	       	if( value=="0")
	       	{
				parent.hiAlert("请选择季别!", '系统提示');
				$("#goodsseason").focus();
				return false;
	        }

			value = $("#goodssize").attr("value");
	       	if( value=="0")
	       	{
				parent.hiAlert("请选择配码!", '系统提示');
				$("#goodssize").focus();
				return false;
	        }

			value = $("#adviceprice").attr("value");
	       	if( value=="")
	       	{
				$adviceprice=0;
			}
			else
		    {
		    	$adviceprice=value;	
	        }

			value=$("#isnewstyle").attr("checked");	
			if (value==true)  
			{
				$isnewstyle=1;
			}
			else
			{
				$isnewstyle=0;
			}	

			value=$("#issale").attr("checked");	
			if (value==true)  
			{
				$issale=1;
			}
			else
			{
				$issale=0;
			}	

			var strSQL = "";                      
			strSQL+= "&goodsid=";
			strSQL+=$("#goodsid").attr("value");
			strSQL+= "&goodsname=";
			strSQL+=$("#goodsname").attr("value");
			strSQL+= "&goodsname_e=";
			strSQL+=$("#goodsname_e").attr("value");
			strSQL+= "&colorid=";
			strSQL+=$("#goodscolor").attr("value");
			strSQL+= "&year=";
			strSQL+=$("#year").attr("value");
			strSQL+= "&season=";
			strSQL+=$("#goodsseason").attr("value");
			strSQL+= "&sort1id=";
			strSQL+=$("#goodssort1").attr("value");
			strSQL+= "&sort2id=";
			strSQL+=$("#goodssort2").attr("value");
			strSQL+= "&sort3id=";
			strSQL+=$("#goodssort3").attr("value");
			strSQL+= "&sort4id=";
			strSQL+=$("#goodssort4").attr("value");
			strSQL+= "&sort5id=";
			strSQL+=$("#goodssort5").attr("value");
			strSQL+= "&sizeid=";
			strSQL+=$("#goodssize").attr("value");
			strSQL+= "&adviceprice="+$adviceprice;
			strSQL+= "&isnewstyle="+$isnewstyle;
			strSQL+= "&issale="+$issale;
			strSQL+= "&remark=";
			strSQL+=$("#remark").attr("value");
			strSQL+= "&remark_e=";
			strSQL+=$("#remark_e").attr("value");
			strSQL+= "&Type=AddGoods";
			
//			alert (strSQL);
			
			$.post("varifyData.php",strSQL,function(msg)
			{

//			    alert (msg);
			    
			   	if (msg=='1')
			   	{	
					parent.hiAlert("数据保存成功!", '系统提示');
					
					$("#goodsid").attr("value","");
					$("#goodsname").attr("value","");
					$("#goodsname_e").attr("value","");
					$("#goodscolor").attr("value","");
					$("#year").attr("value","");
					$("#goodsseason").attr("value","");
					$("#goodssort1").attr("value","");
					$("#goodssort2").attr("value","");
					$("#goodssort3").attr("value","");
					$("#goodssort4").attr("value","");
					$("#goodssort5").attr("value","");
					$("#goodssize").attr("value","");
					$("#adviceprice").attr("value","");
					$("#remark").attr("value","");
					$("#remark_e").attr("value","");

					$("#goodsid").focus();
					return false;
			   	}
			   	else if (msg=='2')
			   	{
//					parent.hiAlert("该货号已经存在!", '系统提示');
//					$("#goodsid").focus();
//					return false;
			   	}
			})
	        
		}

   		function CheckDataEdit(EID)
   		{
			value = $("#goodsid").attr("value");
	       	if( value=="")
	       	{
				parent.hiAlert("请输入货号!", '系统提示');
				$("#goodsid").focus();
				return false;
	        }

			value = $("#goodsname").attr("value");
	       	if( value=="")
	       	{
				parent.hiAlert("请输入品名!", '系统提示');
				$("#goodsname").focus();
				return false;
	        }

			value = $("#goodsname_e").attr("value");
	       	if( value=="")
	       	{
				parent.hiAlert("请输入品名(英文)！", '系统提示');
				$("#goodsname_e").focus();
				return false;
	        }

			value = $("#goodscolor").attr("value");
	       	if( value=="0")
	       	{
				parent.hiAlert("请选择颜色!", '系统提示');
				$("#goodscolor").focus();
				return false;
	        }

			value = $("#goodssort1").attr("value");
	       	if( value=="0")
	       	{
				parent.hiAlert("请选择类别1!", '系统提示');
				$("#goodssort1").focus();
				return false;
	        }

			value = $("#goodssort2").attr("value");
	       	if( value=="0")
	       	{
				parent.hiAlert("请选择类别2!", '系统提示');
				$("#goodssort2").focus();
				return false;
	        }

			value = $("#year").attr("value");
	       	if( value=="")
	       	{
				parent.hiAlert("请输入年份!", '系统提示');
				$("#year").focus();
				return false;
	        }

			value = $("#goodsseason").attr("value");
	       	if( value=="0")
	       	{
				parent.hiAlert("请选择季别!", '系统提示');
				$("#goodsseason").focus();
				return false;
	        }

			value = $("#goodssize").attr("value");
	       	if( value=="0")
	       	{
				parent.hiAlert("请选择配码!", '系统提示');
				$("#goodssize").focus();
				return false;
	        }

			value=$("#isnewstyle").attr("checked");	
			if (value==true)  
			{
				$isnewstyle=1;
			}
			else
			{
				$isnewstyle=0;
			}	

			value=$("#issale").attr("checked");	
			if (value==true)  
			{
				$issale=1;
			}
			else
			{
				$issale=0;
			}	

			var strSQL = "";                      
			strSQL+= "&EID="+EID;
			strSQL+= "&goodsid=";
			strSQL+=$("#goodsid").attr("value");
			strSQL+= "&goodsname=";
			strSQL+=$("#goodsname").attr("value");
			strSQL+= "&goodsname_e=";
			strSQL+=$("#goodsname_e").attr("value");
			strSQL+= "&colorid=";
			strSQL+=$("#goodscolor").attr("value");
			strSQL+= "&year=";
			strSQL+=$("#year").attr("value");
			strSQL+= "&season=";
			strSQL+=$("#goodsseason").attr("value");
			strSQL+= "&sort1id=";
			strSQL+=$("#goodssort1").attr("value");
			strSQL+= "&sort2id=";
			strSQL+=$("#goodssort2").attr("value");
			strSQL+= "&sort3id=";
			strSQL+=$("#goodssort3").attr("value");
			strSQL+= "&sort4id=";
			strSQL+=$("#goodssort4").attr("value");
			strSQL+= "&sort5id=";
			strSQL+=$("#goodssort5").attr("value");
			strSQL+= "&sizeid=";
			strSQL+=$("#goodssize").attr("value");
			strSQL+= "&adviceprice=";
			strSQL+=$("#adviceprice").attr("value");
			strSQL+= "&isnewstyle="+$isnewstyle;
			strSQL+= "&issale="+$issale;
			strSQL+= "&remark=";
			strSQL+=$("#remark").attr("value");
			strSQL+= "&remark_e=";
			strSQL+=$("#remark_e").attr("value");
			strSQL+= "&Type=EditGoods";
			
//			alert (strSQL);
			
			$.post("varifyData.php",strSQL,function(msg)
			{

//			    alert (msg);
			    
			   	if (msg=='1')
			   	{	
					parent.hiAlert("数据保存成功!", '系统提示');
					
					$("#goodsid").focus();
					return false;
			   	}
			   	else if (msg=='2')
			   	{
//					parent.hiAlert("该客服账号已经存在!", '系统提示');
//					$("#userName").focus();
//					return false;
			   	}
			})
	        
	    }    
	</script>
</head>


<body>
	<div id="MenuRighttitle" ><div style="padding-left:245px;padding-top:5px;"><b><?=$Title;?></b></div></div>

	<div class="inner-container">
		<div class="bodypart" style="border:0px solid blue;">	
			<div style="padding-left: 10px; margin-top: 20px; text-align: left; height:auto;border:0px solid blue;">

				<div class="goodsaddnew_a01"><?="产品型号:";?></div>
				<div class="goodsaddnew_a02" ><input type="text" id="goodsid" name="goodsid" value="<?=$result["goodsid"];?>" size="30" maxlength="20" class="goodsaddnew_textbox" style="width:280px;" /></div>

				<div class="goodsaddnew_a01"><b><?="品名:";?></b></div>
				<div class="goodsaddnew_a02" style="width:285px;"><input type="text" id="goodsname" name="goodsname" value="<?=$result["goodsname"];?>" size="30" maxlength="200" class="goodsaddnew_textbox" /></div>

				<div class="goodsaddnew_a01"><b><?="品名(英文):";?></b></div>
				<div class="goodsaddnew_a02" style="width:290px;"><input type="text" id="goodsname_e" name="goodsname_e" value="<?=$result["goodsname_e"];?>" size="30" maxlength="200" class="goodsaddnew_textbox" /></div>

				<div class="goodsaddnew_a01"><b><?="颜色:";?></b></div>
				<div class="goodsaddnew_a02" style="width:100px;">
					<select name="goodscolor" id="goodscolor">
						<option value="0" selected="selected"><?="请选择...";?></option>
					<?
						$strSQL= "select * from color where delflag<>'1' order by id ";  
						$db = MySQL::getInstance('','r-w'); 
						$DBR=$db->query($strSQL); 
						
				      	while($rscolor=$db->fetch($DBR))
				    	{
				    	?>
							<option <?=$result["colorid"]==$rscolor["id"]?"selected":"";?> value="<?=$rscolor["id"];?>"><?=$rscolor["colorname"];?></option>
						<?
						}
					?>
					</select>
				</div>

				<div class="goodsaddnew_a01"><b><?="价格:";?></b></div>
				<div class="goodsaddnew_a02" style="width:100px;"><input type="text" id="adviceprice" adviceprice="year" value="<?=$result["adviceprice"];?>" size="30" class="goodsaddnew_textbox" style="width:95px;" onkeyup="ChangeNum();"/></div>

				<div class="goodsaddnew_a01"><b><?="类别一:";?></b></div>
				<div class="goodsaddnew_a02" style="width:100px;">
					<select name="goodssort1" id="goodssort1">
						<option value="0" selected="selected"><?="请选择...";?></option>
					<?
						$strSQL= "select * from sort1 where delflag<>'1' order by id ";  
						$db = MySQL::getInstance('','r-w'); 
						$DBR=$db->query($strSQL); 
						
				      	while($rscolor=$db->fetch($DBR))
				    	{
				    	?>
							<option <?=$result["sort1id"]==$rscolor["id"]?"selected":"";?> value="<?=$rscolor["id"];?>"><?=$rscolor["sort1name"];?></option>
						<?
						}
					?>
					</select>
				</div>

				<div class="goodsaddnew_a01" style="width:75px;"><b><?="类别二:";?></b></div>
				<div class="goodsaddnew_a02" style="width:120px;">
					<select name="goodssort2" id="goodssort2">
						<option value="0" selected="selected"><?="请选择...";?></option>
					<?
						$strSQL= "select * from sort2 where delflag<>'1' order by id ";  
						$db = MySQL::getInstance('','r-w'); 
						$DBR=$db->query($strSQL); 
						
				      	while($rscolor=$db->fetch($DBR))
				    	{
				    	?>
							<option <?=$result["sort2id"]==$rscolor["id"]?"selected":"";?> value="<?=$rscolor["id"];?>"><?=$rscolor["sort2name"];?></option>
						<?
						}
					?>
					</select>
				</div>

				<div class="goodsaddnew_a01"><b><?="年份:";?></b></div>
				<div class="goodsaddnew_a02" style="width:100px;"><input type="text" id="year" name="year" value="<?=$result["year"];?>" size="30" maxlength="4" class="goodsaddnew_textbox" style="width:95px;" onkeyup="ChangeNum();"/></div>

				<div class="goodsaddnew_a01" style="width:75px;"><b><?="季别:";?></b></div>
				<div class="goodsaddnew_a02" style="width:100px;">
					<select name="goodsseason" id="goodsseason">
						<option value="0" selected="selected"><?="请选择...";?></option>
					<?
						$strSQL= "select * from season where delflag<>'1' order by id ";  
						$db = MySQL::getInstance('','r-w'); 
						$DBR=$db->query($strSQL); 
						
				      	while($rscolor=$db->fetch($DBR))
				    	{
				    	?>
							<option <?=$result["season"]==$rscolor["id"]?"selected":"";?> value="<?=$rscolor["id"];?>"><?=$rscolor["season"];?></option>
						<?
						}
					?>
					</select>
				</div>

				<div class="goodsaddnew_a01"><b><?="类别三:";?></b></div>
				<div class="goodsaddnew_a02" style="width:100px;">
					<select name="goodssort3" id="goodssort3">
						<option value="0" selected="selected"><?="请选择...";?></option>
					<?
						$strSQL= "select * from sort3 where delflag<>'1' order by id ";  
						$db = MySQL::getInstance('','r-w'); 
						$DBR=$db->query($strSQL); 
						
				      	while($rscolor=$db->fetch($DBR))
				    	{
				    	?>
							<option <?=$result["sort3id"]==$rscolor["id"]?"selected":"";?> value="<?=$rscolor["id"];?>"><?=$rscolor["sort3name"];?></option>
						<?
						}
					?>
					</select>
				</div>

				<div class="goodsaddnew_a01" style="width:75px;"><b><?="类别四:";?></b></div>
				<div class="goodsaddnew_a02" style="width:120px;">
					<select name="goodssort4" id="goodssort4">
						<option value="0" selected="selected"><?="请选择...";?></option>
					<?
						$strSQL= "select * from sort4 where delflag<>'1' order by id ";  
						$db = MySQL::getInstance('','r-w'); 
						$DBR=$db->query($strSQL); 
						
				      	while($rscolor=$db->fetch($DBR))
				    	{
				    	?>
							<option <?=$result["sort4id"]==$rscolor["id"]?"selected":"";?> value="<?=$rscolor["id"];?>"><?=$rscolor["sort4name"];?></option>
						<?
						}
					?>
					</select>
				</div>

				<div class="goodsaddnew_a01"><b><?="新款:";?></b></div>
				<div class="goodsaddnew_a02" style="width:100px;"><input type="checkbox" name="isnewstyle" id="isnewstyle" <?=$result["isnewstyle"]=='1'?'checked':'';?> value="<?=$result["isnewstyle"];?>" style="margin-top:3px;"></div>

				<div class="goodsaddnew_a01" style="width:75px;"><b><?="促销:";?></b></div>
				<div class="goodsaddnew_a02" style="width:100px;"><input type="checkbox" name="issale" id="issale" <?=$result["issale"]=='1'?'checked':'';?> value="<?=$result["issale"];?>" style="margin-top:3px;"></div>

				<div class="goodsaddnew_a01"><b><?="类别五:";?></b></div>
				<div class="goodsaddnew_a02" style="width:100px;">
					<select name="goodssort5" id="goodssort5">
						<option value="0" selected="selected"><?="请选择...";?></option>
					<?
						$strSQL= "select * from sort5 where delflag<>'1' order by id ";  
						$db = MySQL::getInstance('','r-w'); 
						$DBR=$db->query($strSQL); 
						
				      	while($rscolor=$db->fetch($DBR))
				    	{
				    	?>
							<option <?=$result["sort5id"]==$rscolor["id"]?"selected":"";?> value="<?=$rscolor["id"];?>"><?=$rscolor["sort5name"];?></option>
						<?
						}
					?>
					</select>
				</div>
				<div class="goodsaddnew_a01"><b><?="配码:";?></b></div>
				<div class="goodsaddnew_a02" style="width:120px;">
					<select name="goodssize" id="goodssize">
						<option value="0" selected="selected"><?="请选择...";?></option>
					<?
						$strSQL= "select * from size where delflag<>'1' order by id ";  
						$db = MySQL::getInstance('','r-w'); 
						$DBR=$db->query($strSQL); 
						
				      	while($rscolor=$db->fetch($DBR))
				    	{
				    	?>
							<option <?=$result["sizeid"]==$rscolor["id"]?"selected":"";?> value="<?=$rscolor["id"];?>"><?=$rscolor["remark"];?></option>
						<?
						}
					?>
					</select>
				</div>
				

				<div class="goodsaddnew_a01" style="height:100px;line-height:100px;"><b><?="产品说明:";?></b></div>
				<div class="goodsaddnew_a02" style="height:100px;width:286px;">
					<textarea name="remark" id="remark" style="float:left;width:280px;height:100px;" cols="50" rows="5" class="goodsaddnew_textbox"><?=$result["remark"];?></textarea>
				</div>

				<div class="goodsaddnew_a01" style="height:100px;line-height:100px;"><b><?="说明(英文):";?></b></div>
				<div class="goodsaddnew_a02" style="height:100px;width:280px;">
					<textarea name="remark_e" id="remark_e" style="float:left;width:280px;height:100px;" cols="50" rows="5" class="goodsaddnew_textbox"><?=$result["remark_e"];?></textarea>
				</div>

				<div class="goodsaddnew_a01"></div>
				<div class="goodsaddnew_a02"></div>
				<div class="goodsaddnew_a01"></div>
				<div class="goodsaddnew_a02"></div>

				<div class="goodsaddnew_a01" style="margin-top: 20px;width:750px;text-align:center;border:0px solid blue;">
					<?
					if ($Type==0)
					{
					?>
						<input type="image" name="image" value="image" src="images/submit_btn.gif" onclick="javascript:CheckData();" /> 
					<?
					}
					else if ($Type==1)
					{
					?>
						<input type="image" name="image" value="image" src="images/submit_btn.gif" onclick="javascript:CheckDataEdit('<?=$result["id"];?>');" />
					<?
					}
					?>


					<input type="image" name="image" value="image" src="images/go_btn.gif" onclick="javascript:goback('<?=$pgno;?>');" /> 
				</div>
			</div>
		</div>
	</div>
</body>

</html>
